1. Field of the Invention
The present invention generally relates to computer systems, particularly to a method of creating computer programs using programming languages, and more specifically to a method of defining a script macro using an object-oriented programming language such that the script macro may be used on multiple sets of objects.
2. Description of Related Art
A generalized structure for a conventional computer system includes one or more processing units connected to a system memory device (random access memory or RAM) and to various peripheral, or input/output (I/O), devices. The I/O devices typically include a display monitor, a keyboard, a graphical pointer (mouse), and a permanent storage device (hard disk). The system memory device is used by a processing unit in carrying out program instructions, and stores those instructions as well as data values that are fed to or generated by the programs. A processing unit communicates with the other components by various means, including one or more interconnects (buses), or direct access channels. A computer system may have many additional components, such as serial and parallel ports for connection to, e.g., printers, and network adapters. Other components might further be used in conjunction with the foregoing; for example, a display adapter might be used to control a video display monitor, a memory controller can be used to access the system memory, etc.
A computer program is accordingly a set of program instructions which are adapted to perform certain functions acting upon, or in response to, the I/O devices. Program instructions that are carried out by the processor are, at that lowest level, binary in form, i.e., a series of ones and zeros. These executable (machine-readable) program instructions are produced from higher-level instructions written in a programming language. The programming language may still be low-level, such as assembly language (which is difficult to use since instructions appear as hexadecimal bytes), or may be a higher level language in which instructions are created using more easily understood words and symbols. One example of a high level programming language is xe2x80x9cCxe2x80x9d (or its improved version xe2x80x9cC++xe2x80x9d). After a computer program is written in C++, it is converted into machine code using a compiler (which reduces the high-level code into assembly language) and a linker (which transforms the assembly language into machine code).
In an attempt to simplify programming, and yet still provide powerful development tools, programmers have created xe2x80x9cobject-orientedxe2x80x9d programming languages, in which each variable, function, etc., can be considered an object of a particular class. C++ is an example of an object-oriented programming language, and provides advanced programming features such as polymorphism, encapsulation, and inheritance. This programming language also allows the use of a xe2x80x9cmacro,xe2x80x9d that is, a name that defines a set of instructions that are substituted for the macro name wherever the name appears in a program (a process called macro expansion) when the program is compiled or assembled. Macros are similar to functions in that they can take arguments, and in that they are calls to lengthier sets of instructions. Unlike functions, macros are replaced by the actual instructions they represent when the program is prepared for execution.
xe2x80x9cJavaxe2x80x9d is another object-oriented programming language, developed by Sun Microsystems, Inc. Java is similar to the C++ programming language, but Java is smaller, more portable, and easier to use than C++ because it manages memory on its own. Java programs are compiled into bytecodes, which are similar to machine code but are not specific to any platform. Currently, the most widespread use of Java is in programming small applications (applets) for the World Wide Web of the Internet. These applets do not run as separate programs, but rather are loaded within another application that has Java support, such as a web browser. The term xe2x80x9cappletxe2x80x9d is particularly utilized to refer to such programs as they are embedded in-line as objects in hypertext markup language (HTML) documents.
Portions of Java code (components) which are self-contained, and can often be re-used in different applets, are sometimes referred to as xe2x80x9cbeans.xe2x80x9d Such components can be visually composed into units using visual application builder tools. Java builder tools can maintain beans in a palette or toolbox, and a particular bean can be selected from the toolbox, dropped into an applet or other component (such as a form), and its behavior defined, all without writing any actual code.
While programming languages are used to create an application, developers also utilize xe2x80x9cscriptingxe2x80x9d languages to design a script, or set of instructions (commands), used by a particular application to perform a specific task. FIG. 1 is a generic diagram showing the relationship of a script 10 to an application 12 (which may include an applet 14), the computer""s operating system 16, and the hardware 18 (viz., the processor). Script 10 feeds commands to application 12 (or applet 14), and operating system 16 manages execution of the application""s processing of script 10. In other words, the computer""s hardware 18 is first initialized using operating system 16, which then acts as a platform to load application 12; after application 12 has been loaded, it reads and executes the commands in script 10. An example of an early scripting language is PERL (Practical Extraction and Report Language), an interpreted language based on C and UNIX. PERL can assemble a string and send it to an application or operating shell as a command.
Another example of a scripting language is JavaScript, developed by Netscape Communications and Sun Microsystems. JavaScript, while somewhat related to Java, is not an object-oriented language. JavaScript complements Java by exposing useful properties of Java applets to script authors. JavaScript scripts embedded directly in HTML documents can get and set exposed properties in order to query the state or alter the performance of an applet, as shown in FIG. 2. In this example, the HTML page 19 specifies the parameter xe2x80x9ccommandxe2x80x9d for the name of the JavaScript function to be called when a date is selected.
Existing applications that have scripting ability (including browsers that support JavaScript) connect a set of predefined, named objects to the script. It is possible to rename an object but it is not possible to assign a new object for a given name. In other words, current scripting applications do not allow a script writer to define a script macro which has some script for a set of generic named objects, and which can hence work on various sets of objects that conform to certain conditions predefined in the script macro. It would, therefore, be desirable to devise a method of defining a script macro such that the script macro may be used on multiple sets of objects. It would be further advantageous if the script macro could be instantiated/restored without instantiating its objects.
It is therefore one object of the present invention to provide an improved method of developing computer programs.
It is another object of the present invention to provide such a method which can be implemented with an object-oriented programming language and a script code.
It is yet another object of the present invention to provide such a method using a script macro, wherein object instances are not bound with.:the script macro, but rather are supplied at runtime.
The foregoing objects are achieved in a method of providing instructions to an application running on a computer system, generally comprising the steps of creating an object-oriented scripting environment which allows a user to enter separate code as a script, registering one or more objects with the scripting environment using a script macro, and instantiating the objects at runtime using a script code. The method allows re-use of the script macro to instantiate multiple sets of objects named in the script code. The registering step may register the objects with only names and classes; the objects are then instantiated by determining one or more classes of the one or more objects, and rebuilding class information in a memory device of the computer system.
In the illustrative embodiment, the application is designed using an object-oriented programming language, and the script code is written in the same object-oriented programming language. More specifically, the application is a Java applet which includes the script macro, and the instantiating step includes the step of instantiating a Java bean named in the script code. The Java bean may be instantiated by first determining its attributes, and then invoking the bean using a customizer.
The above as well as additional objectives, features, and advantages of the present invention will become apparent in the following detailed written description.